﻿namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {

            
            int x = 0;//设置初始横坐标
            int y = 0;//设置初始纵坐标
            while (true)
            {
                

                char direction = Console.ReadKey(true).KeyChar;
                Console.Clear();
                Console.SetCursorPosition(x, y);
                
                switch (direction)
                {
                    case 'A':
                    case 'a':
                        x -=1;
                        if (x < 0)
                            x = 0;
                        break;
                    case 'W':
                    case 'w':
                        y -= 1;
                        if (y < 0)
                            y = 0;
                        break;
                    // 光标的位置坐标必须小于窗口边界，因此要进行边界处理
                    case 'S':
                    case 's':
                        y += 1;
                        if (y > Console.WindowHeight)
                            y = Console.WindowHeight;
                        break;
                    case 'D':
                    case 'd':
                        x += 1;
                        if (x > Console.WindowWidth - 5)       // 横纵轴比例不同
                            x = Console.WindowWidth - 5;
                        break;
                    case 'Q':
                    case 'q':
                        Environment.Exit(0);
                    
                        break;
                    default:
                        break;
                }
                Console.SetCursorPosition(x, y);
                Console.WriteLine("Hello");
                Console.SetCursorPosition(90, 20);
                Console.WriteLine("({0},{1})", x, y);
                Console.SetCursorPosition(90, 21);
                Console.WriteLine("输入q以退出");

            }
       
        }
    }
}